<template>
  <div>
    <el-table :data="tableData" style="width: 100%" v-loading="loading">
      <el-table-column
        prop="complaintContent"
        align="center"
        label="投诉内容"
        width="180"
      />
      <el-table-column prop="complaintType" align="center" label="投诉类型" />
      <el-table-column prop="remark" align="center" label="备注" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)"
            >编辑备注</el-button
          >
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 换页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改班级信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  addComplaint,
  delComplaint,
  updateComplaint,
  listComplaint,
} from "@/api/taa/complaintManagement";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      total: null,
      // 总条数
      total: 0,
      tableData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 分页
      pageNum: 1,
      pageSize: 10,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        remark: null,
      };
      this.resetForm("form");
    },
    // 查询投诉信息
    getList() {
      this.loading = true;
      listComplaint(this.queryParams).then((res) => {
        this.total = res.total;
        this.tableData = res.rows;
        this.loading = false;
      });
    },
    // 修改按钮操作
    handleEdit(row) {
      this.reset();
      // console.log("asdas", row);
      // this.form = row
      // this.open = true;
      // this.title = "修改备注";
      this.form = JSON.parse(JSON.stringify(row));
      this.open = true;
      this.title = "修改班级信息";
    },
    /** 提交按钮 */
    submitForm() {
      updateComplaint(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.complaintId;
      this.$modal
        .confirm('是否确认删除班级信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delComplaint(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(
            "逻辑删除成功（注：删除操作成功，但数据依旧存在）"
          );
        })
        .catch(() => {});
    },
  },
};
</script>